/**
 * Created by zhengsenwen on 2017/8/24.
 */

flush();

function flush() {

    setTimeout(function () {
        $.ajax({
            type: 'get',
            url: '/restaurant/restaurantInfoList',
            async: 'true',
            timeout: '10000',
            data: {},
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                putDataInHtml(data);
            },
            error: function () {
                alert("失败，请稍后再试！");
            }
        });

        loadCopyrightFirst();

    }, 500);

    setInterval(function () {
        $.ajax({
            type: 'get',
            url: '/restaurant/restaurantInfoList',
            async: 'true',
            timeout: '10000',
            data: {},
            contentType: 'application/json;charset=utf-8',
            beforeSend: function () {
                $(".restaurant_box").empty();
            },
            success: function (data) {
                putDataInHtml(data);
            },
            error: function () {
                alert("失败，请稍后再试！");
            }
        });

        loadCopyrightSecond();

        //测试1000 * 5  实际 1000 * 60 * 60
    }, 1000 * 60 * 60);
}

function putDataInHtml(data) {

    $(data).each(function (i, value) {
        var drInfo = data[i].drInfo;

        var div = '<div class="box" id="restaurant_div">' +
            '<ul id="restaurant_ul">' +
            '<li><img src="/image/point.png"/>' +
            '<span>可容纳人数：</span><span style="color: #ffb217">' + drInfo.drMealNum + '</span>' +
            '</li>' +
            '<li><img src="/image/point.png"/>' +
            '<span>当前剩余座位数：</span><span style="color: #3aff0f" >' + drInfo.drFreeNum + '</span>' +
            '</li>' +
            '<li><img src="/image/point.png"/>' +
            '<span>推荐就餐时间：</span>' +
            '<span id="recommendedMealTime" style="color: yellow">' + data[i].recommendedMealTime + '</span>' +
            '</li>' +
            '</ul>' +
            '<a style="display: block;" href="/view/diningroom/' + drInfo.id + '" >' +
            '<img id="restaurant_img" src="/myResources/' + drInfo.drPic + '" alt="">' +
            '</a>' +
            '</div>';

        $(".restaurant_box").append(div);
    });

    $("#restaurant_div  #restaurant_img").bind("error", function () {
        this.src = "/image/error.jpg";
    });

}
